#pragma once

#ifdef _WINDOWS_
#undef _WINDOWS_
#include <afxwin.h>
#include <afxext.h>
#include "resource.h"

#define BOOL int
#define TRUE 1
#define FALSE 0

#endif
//#include "Render\Render.h"
//#include "Common\Viewer.h"

#define KEY_UP			1
#define KEY_DOWN		2
#define KEY_ON_RELEASE	3
#define KEY_ON_PRESSED	4

class CWindow {

	static const std::string g_WindowTitle;

	class CMFCChildWindow : public CWnd {
	
	public:
		CMFCChildWindow();
		virtual ~CMFCChildWindow();

	protected:
		virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
		void OnPaint();
		BOOL OnEraseBkgnd(CDC* pDC);
		void OnMouseMove(UINT nFlags, CPoint point);
		void OnLButtonDown(UINT nFlags, CPoint point);
		void OnKeyDown(UINT nChar, UINT nRepCount, UINT nFlags);
		void OnKeyUp(UINT nChar, UINT nRepCount, UINT nFlags);
		void OnKeyEvent(UINT nChar, UINT nFlags, bool isDown);
		void OnToolbarDropDown(NMHDR* pnmtb, LRESULT *plr);
		void GetClientCursor(CPoint* pOut, CPoint point);
		DECLARE_MESSAGE_MAP()
	};

	class CMFCWindow : public CFrameWnd {

	private:
		
	public:
		CMFCChildWindow    m_wndView;
		CMFCWindow();
		int OnCreate(LPCREATESTRUCT lpCreateStruct);
	
		void OnSetFocus(CWnd*);

		BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
			
		DECLARE_MESSAGE_MAP()

	};

	class CMFCInst : public CWinApp {

	public:
		BOOL InitInstance();
		INT ExitInstance();

		//int Run();
		BOOL OnIdle(LONG lCount);
	};

	static CMFCInst g_ApplicationInstance;
	static CMFCWindow *g_ApplicationWindow; 
	static UINT g_Keyboard [256];

	static void (*g_pKeyboardEventHandler)(UINT *pKeyboardState);
	static void (*g_pMouseEventHandler)(const int dxMouse, const int dyMouse, const int leftButton, const int rightButton);

	//static bool g_MouseBlock;

public:

	static void Close();
	static void Move();

	static void ResetEventState();

	static BOOL IsWindowMinimized();

	static HWND GetHandle();

	static void CenterMouse();
	static POINT GetMousePosition();
	static INT GetMouseWheelDelta();
	
	static BOOL IsKeyDown(DWORD button);
	static BOOL IsKeyPressed(DWORD button);
	static BOOL IsKeyReleased(DWORD button);

	static void GetClientRectangle(RECT* pRect);

};

LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(	HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPSTR     lpCmdLine,
				   int       nCmdShow );

LRESULT CALLBACK WindowProc( HWND   hWnd, UINT   msg, WPARAM wParam, LPARAM lParam );